package linkenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义常量
const (
	// 待发布
	STATUS_PENDING int = 11

	// 已发布
	STATUS_PUBLISH int = 22
)

// 实现EnumInerface接口
type Status struct {
	enum.Enum[int]
}

func (e *Status) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		STATUS_PENDING: {
			"desc":  "待发布",
			"sort":  1,
			"color": "#16baaa",
		},
		STATUS_PUBLISH: {
			"desc":  "已发布",
			"sort":  2,
			"color": "#ffb800",
		},
	}
}

// instanceCache 存储已经创建的实例
var statusInstanceCache = make(map[int]*Status)

// 创建枚举
// 根据value获取枚举
func StatusByValue(value int) *Status {
	if instance, exists := statusInstanceCache[value]; exists {
		return instance
	}
	e := &Status{}
	enum.SetEnumInstance(&e.Enum, e, value)
	statusInstanceCache[value] = e
	return e
}

var StatusEnum *Status = func() *Status {
	e := &Status{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
